package com.example.controller;

import com.example.pojo.Collection;
import com.example.pojo.Result;
import com.example.service.impl.CollectionServiceImpl;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@CrossOrigin
@Slf4j
@RequestMapping("/collection")
@RestController
public class CollectionController {
    @Autowired
    private CollectionServiceImpl collectionService;

    @Autowired
    private HttpServletRequest request;

    //添加收藏
    @PostMapping
    public Result addConllection(@RequestBody Collection collection){
        collectionService.addConllection(collection,request);
        return Result.success();
    }

    //个人收藏
    @GetMapping
    public Result getCollection(String name, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime date){
        List<Collection> list=collectionService.getCollection(name,date,request);
        return Result.success(list);
    }

    //删除收藏
    @DeleteMapping("/{id}")
    public Result delCollection(@PathVariable Integer id){
        collectionService.delCollection(id,request);
        return Result.success();
    }
}
